home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c++
- Subject: Re: beginner question - typecasting
- Date: 04 Jan 1996 22:33:57 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan4173357@g7240065.bridge.bst.bls.com>
- References: <4cei1r$s02@sun.cis.smu.edu> <30EBCED7.774@sto.fdata.se>
- <4che01$kjm@colossus.holonet.net>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: russell@news.mdli.com's message of 4 Jan 1996 20:40:33 GMT
-
- Russell Blackadar (russell@news.mdli.com) wrote:
- : Niklas Mellin (niklas.mellin@sto.fdata.se) wrote:
- :: Damon Bowman wrote:
-
- ::> When you are typecasting, is there any difference between:
-
- ::> a = int(x)
- ::> and
- ::> a = (int) x
- :: [...]
- : [...]
-
- :: The 2nd form is an inheritance from plain C, and doesn't work
- :: when x is of class type...
-
- : Ahem, this is wrong. Both forms are valid in C++, and both
- : invoke the class's operator int. There is absolutely no
- : functional difference between the two forms. It would be
- : nice to have just one syntax to convert types, but since C
- : supports both, C++ must also. Take a look at the ARM, please.
-
- C does not support both !
- The first form was introduced by C++.
-
- As Russell states there is absolutely no functional difference between the
- two forms - but should there be ?
-
- Example:
-
- class A
- {
- public:
- ...
- A(const B& b);
- ...
- };
-
- class B
- {
- public:
- ...
- operator A (void);
- ...
- };
-
- Couldn't the different syntax be used to disambiguate this problem:
-
- a = A(b); // should call A constructor.
- a = (A)b; // should call B type operator.
-
- Instead of
-
- a = A(b); // Error: 2 possible conversion for b;
- a = (A)b; // Error: 2 possible conversion for b;
-
- Just idle thoughts
- Regards
-
- -A.
- --
- | A.Champion |
-